package service;

import model.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginCheck {
    public int check(User user) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        int res = 0;
        try {
            connection = JDBCConnect.getConnection();
            String sql = "select * from users where id = ? AND pwd = ?";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1, user.getId());
            preparedStatement.setString(2, user.getPwd());
            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                res = 1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return res;
    }
}
